import wepy from 'wepy';
const get = (url, data, header) => {
    header = header ? header : {};
    return Ajax(url, 'GET', data, header);
}

const post = (url, data, header) => {
    header = header ? header : {};
    header['Content-Type'] = 'application/x-www-form-urlencoded';
    return Ajax(url, 'POST', data, header);
}

const Ajax = (url, method, data, header) => {
    let cfg = wepy.getStorageSync('cfg');
    url = cfg.serverHost + url;
    header = header ? header : {};

    return new Promise((resolve, reject) => {
        wepy.request({
            url: url,
            data: data,
            method: method,
            header: header
        }).then(res => {
            if (res.status == 0) {
                resolve(res);
            } else {
                reject(res)
            }
        }, error => {
            reject(error);
        })
    })
}
export default {
    get,
    post
}